#ifndef SWANLINK_FINANCE_FRAMEWORKS_CLIENT_OBSERVER_H
#define SWANLINK_FINANCE_FRAMEWORKS_CLIENT_OBSERVER_H
#include <js_native_api.h>
#include <js_native_api_types.h>
#include <napi/native_common.h>
#include <napi/native_api.h>
#include <mutex>
#include <nocopyable.h>
#include <string>
#include <vector>
#include <stack>

#include "recptprinter_observer_stub.h"

namespace SwanLink {
namespace Finance {
using namespace OHOS;

class NapiPrintListener {
 public:
  NapiPrintListener();
  ~NapiPrintListener();
  napi_env  env;
  napi_ref  func_succ_ref;
  napi_ref  func_fail_ref;

  void OnSuccess(int proc, int total);
  void OnFailed(int code, const std::string& err);
};

class PrinterObserver: public RecptprinterObserverStub {
 public:
  PrinterObserver();
  virtual ~PrinterObserver();

  void PushObserver(const napi_env &env, const napi_value &listener);
  void PopObserver();

  void OnSuccess(int proc, int total) override;
  void OnFailed(int code, const std::string& err) override;

  DISALLOW_COPY(PrinterObserver);
 private:
  NapiPrintListener*  listener_;
  std::mutex  mutex_;
};
}  // namespace Finance
}  // namespace SwanLink
#endif  // SWANLINK_FINANCE_FRAMEWORKS_CLIENT_OBSERVER_H
